package cn.kc.jdbc.service;

import cn.kc.jdbc.dao.*;
import cn.kc.jdbc.entity.Course;
import cn.kc.jdbc.entity.Score;
import cn.kc.jdbc.entity.Student;

import java.util.List;

/**
 * @author mosin
 * date 2022/2/14
 * @version 1.0
 */
public class ScoreServiceImpl implements ScoreService {

    private ScoreDao scoreDao = new ScoreDaoImpl();
    private  StudentDao studentDao = new StudentDaoImpl();
    private CourseDao courseDao =  new CourseDaoImpl();

    @Override
    public Boolean addScore(String stuName, String courseName,Double score) {

        //添加成绩   stu_id  subject_id   score
        // 1.根据学生的名字 查询学生 id
        Student student = studentDao.selectOne(stuName);
        // 2.根据课程名字 查询课程id
        Course course = courseDao.findCourseByCourseName(courseName);
        //3. 将 stu_id  subject_id   score 插入到成绩表
       Integer line = scoreDao.addScore(student.getId(),course.getCourseId(),score);
        return  line>0;
    }

    @Override
    public List<Score> findAllScore(String courseName) {
        /**
         *根据科目名称查询学生成绩
         */

        List<Score> scores = scoreDao.findAllScores(courseName);

        return scores;
    }
}
